package com.freeheart.aop.basevalid;


import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 使用Spring AOP定义Advice，统一对实现`BaseValid`接口的参数类做统一校验。
 * 因为：需要用户指定校验的包名。所以，不能使用AspectJ的AOP定义方式
 *
 * @author: EmperorHeart
 * @date: 2025/4/4 20:21
 * @description
 */
public class BaseValidInterceptor implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Object[] arguments = invocation.getArguments();
        for (Object argument : arguments) {
            if (argument instanceof BaseValid baseValid) {
                baseValid.valid();
            }
        }
        return invocation.proceed();
    }
}
